package uit.edu.vn.portal.elearning.helper;

import java.util.ArrayList;
import java.util.List;

import uit.edu.vn.portal.elearning.logic.SakaiWSLogic;
import uit.edu.vn.portal.elearning.models.course.Site;
import uit.edu.vn.portal.elearning.models.course.Tool;
import uit.edu.vn.portal.elearning.models.announcement.Announcement;
import uit.edu.vn.portal.elearning.models.assignment.Assignment;
import uit.edu.vn.portal.elearning.models.schedule.CalendarEvent;

public class SakaiWSHelper {
	
	public static String getRemoteUserId(SakaiWSLogic logic){
		return logic.getRemoteUserIdForUser();
	}
	
	public static List<Site> getAllSitesForUser (SakaiWSLogic logic){
		return logic.getAllSitesForUser();
	}
	
	public static List<Site> getAllJoinableSitesForUser(SakaiWSLogic logic){
		return logic.getAllJoinableSitesForUser();
	}
	
	public static String addNewSite(SakaiWSLogic logic, String siteid, String title, String description, 
			String shortdesc, String iconurl, String infourl, String joinable, 
			String joinerrole, String published, String publicview, String skin, String type){
		return logic.addNewSite(siteid, title, description, shortdesc, iconurl, infourl, joinable, joinerrole, published, publicview, skin, type);
	}
	
	public static String addNewPageToSite(SakaiWSLogic logic, String siteid, String pagetitle, int pagelayout){
		return logic.addNewPageToSite(siteid, pagetitle, pagelayout);
	}
	
	public static String addNewToolToPage(SakaiWSLogic logic, String siteid, String pagetitle, String tooltitle, String toolid, String layouthints){
		return logic.addNewToolToPage(siteid, pagetitle, tooltitle, toolid, layouthints);
	}
	
	public static String addMemberToSiteWithRole(SakaiWSLogic logic, String siteid, String userid, String roleid){
		return logic.addMemberToSiteWithRole(siteid, userid, roleid);
	}
	
	public static List<Tool> getToolsForSite(SakaiWSLogic logic, String siteId) {
		return logic.getToolsForSite(siteId);
	}
	
	public static List<Announcement> getAnnouncements(SakaiWSLogic logic){
		List<Site> allSites = logic.getAllSitesForUser(); 
		List<Announcement> result = new ArrayList<Announcement>();
		
		for(Site site: allSites){
			List<Announcement> tmp = logic.getAnnouncementsForSite(site.getId());
			result.addAll(tmp);
		}
		
		return result;
	}
	
	public static List<CalendarEvent> getSchedules(SakaiWSLogic logic){
		List<Site> allSites = logic.getAllSitesForUser(); 
		List<CalendarEvent> result = new ArrayList<CalendarEvent>();
		
		for(Site site: allSites){
			List<CalendarEvent> tmp = logic.getSchedulesForSite(site.getId());
			result.addAll(tmp);
		}
		
		return result;
	}
	
	public static List<Assignment> getAssignments(SakaiWSLogic logic){
		List<Site> allSites = logic.getAllSitesForUser(); 
		List<Assignment> result = new ArrayList<Assignment>();
		
		for(Site site: allSites){
			List<Assignment> tmp = logic.getAssignmentsForSite(site.getId());
			result.addAll(tmp);
		}
		
		return result;
	}
	
	public static String getSiteTitle(SakaiWSLogic logic,String siteid){
		return logic.getSiteTitle(siteid);
	}
	
	public static String test(SakaiWSLogic logic){
		return "Ok!";
	}
}
